<?php
class AlertWidget extends CWidget
{
    public $showPopupMessage = true;
    
    public $showMessageDiv = true;
    
    public function run()
    {        
        $keys = array(      
            'success' => 'Success',
            'info' => 'Info',
            'warning' => 'Warning',
            'error' => 'Error',
        );

        foreach($keys as $k => $title){
            if($msg = Yii::app()->user->getFlash($k)){
                if($this->showMessageDiv)
                    echo '<div class="da-message '.$k.'">'.$msg.'</div>';
            
                
                if($this->showPopupMessage) {
                    $cs = Yii::app()->clientScript;
                    $cs->registerCssFile($this->controller->themeUrl . '/files/theme/plugins/jgrowl/jquery.jgrowl.css');
                    $cs->registerScriptFile($this->controller->themeUrl . '/files/theme/plugins/jgrowl/jquery.jgrowl.min.js');
                    $cs->registerScript('jGrow', '
                        $.jGrowl("'.$msg.'", {
                            header: "'.$title.'",
                            position: "bottom-right"
                        });
                    ');
                }
                break;
            }
        }
    }
}
?>
